﻿#include "customwebview.h"
#include "browsermainwindow.h"

CustomWebView::CustomWebView(QWidget *parent)
    : QWebEngineView(parent)
{

}


QWebEngineView *CustomWebView::createWindow(QWebEnginePage::WebWindowType type)
{
        BrowserMainWindow *mainWindow = qobject_cast<BrowserMainWindow*>(window());
        qDebug() << "create windows: " << type;
        switch (type) {
            case QWebEnginePage::WebBrowserTab: {
//                return mainWindow->tabWidget()->createTab();
                return mainWindow->tabWidget()->createTab();
            }
            case QWebEnginePage::WebBrowserBackgroundTab: {
//                return mainWindow->tabWidget()->createBackgroundTab();
                return mainWindow->tabWidget()->createTab();
//                return nullptr;
            }
            case QWebEnginePage::WebBrowserWindow: {
                //return mainWindow->explore()->createWindow()->currentTab();
                 return mainWindow->tabWidget()->createTab();
//                return nullptr;
            }
            case QWebEnginePage::WebDialog: {
//                return mainWindow->explore()->createWindow()->currentTab();
                return mainWindow->tabWidget()->createTab();
            }
        }
        return nullptr;
}

//QWebEngineView *CustomWebView::createWindow(QWebEnginePage::WebWindowType type)
//{
//    BrowserMainWindow *mainWindow = qobject_cast<BrowserMainWindow*>(window());
//    if (!mainWindow)
//        return nullptr;

//    switch (type) {
//        case QWebEnginePage::WebBrowserTab: {
//            return mainWindow->tabWidget()->createTab();
//        }
//        case QWebEnginePage::WebBrowserBackgroundTab: {
//            return mainWindow->tabWidget()->createBackgroundTab();
//            return mainWindow->tabWidget()->createTab();
//        }
//        case QWebEnginePage::WebBrowserWindow: {
//            //return mainWindow->explore()->createWindow()->currentTab();
//             return mainWindow->tabWidget()->createTab();
//        }
//        case QWebEnginePage::WebDialog: {
//            return mainWindow->explore()->createWindow()->currentTab();
//            return mainWindow->tabWidget()->createTab();
//        }
//    }
//    return nullptr;
//}
